import Vue from 'vue'
import Router from 'vue-router'
import Login from './views/Login.vue'
import Main from './views/Main.vue'
import FlightEdit from './views/FlightEdit.vue'
import FlightList from './views/FlightList.vue'

import ArticleEdit from './views/ArticleEdit.vue'
import ArticleList from './views/ArticleList.vue'

import AdminUserEdit from './views/AdminUserEdit.vue'
import AdminUserList from './views/AdminUserList.vue'

import CustomUserEdit from './views/CustomUserEdit.vue'
import CustomUserList from './views/CustomUserList.vue'

import Show from './views/Show.vue'
import ShowMoney from './views/ShowMoney.vue'
Vue.use(Router)

const router = new Router({
  routes: [
    {path:'/login',name:'login',component:Login,meta:{isPublic:true}},
    {
      path: '/',
      name: 'main',
      component: Main,
      children:[
        {path:'/flights/create',component:FlightEdit},
        {path:'/flights/edit/:id',component:FlightEdit,props:true},
        {path:'/flights/list',component:FlightList},

        {path:'/articles/create',component:ArticleEdit},
        {path:'/articles/edit/:id',component:ArticleEdit,props:true},
        {path:'/articles/list',component:ArticleList},

        {path:'/admin_users/create',component:AdminUserEdit},
        {path:'/admin_users/edit/:id',component:AdminUserEdit,props:true},
        {path:'/admin_users/list',component:AdminUserList},

        {path:'/custom_users/create',component:CustomUserEdit},
        {path:'/custom_users/edit/:id',component:CustomUserEdit,props:true},
        {path:'/custom_users/list',component:CustomUserList},

        {path:'/admin_users/show',component:Show},
        {path:'/admin_users/show_money',component:ShowMoney},
      ]
    },
    
  ]
})
router.beforeEach((to,from,next)=>{
  if(!to.meta.isPublic && !localStorage.token){
    return next('/login')
  }
  next()
})
export default router
